﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity;

namespace Acme.BookStore2.Controllers
{
    [Area("identity")]
    [ControllerName("User")]
    [Route("api/identity/users")]
    public class ExtendIdentityUserController : BookStore2Controller, IExtendIdentityUserAppService
    {
        private readonly IExtendIdentityUserAppService _identityUserAppService;

        public ExtendIdentityUserController(IExtendIdentityUserAppService identityUserAppService)
        {
            _identityUserAppService = identityUserAppService;
        }

        [HttpPut]
        [Route("{id}/change-password")]
        public Task ChangePasswordAsync(Guid id, IdentityChangePasswordInput input)
        {
            return _identityUserAppService.ChangePasswordAsync(id, input);
        }

        [HttpPost]
        [Route("extend")]
        public Task<IdentityUserDto> CreateAsync(ExtendIdentityUserCreateDto input)
        {
            return _identityUserAppService.CreateAsync(input);
        }

        [HttpGet]
        [Route("assignable-organization-units")]
        public Task<ListResultDto<OrganizationUnitDto>> GetAssignableOrganizationUnitsAsync()
        {
            return _identityUserAppService.GetAssignableOrganizationUnitsAsync();
        }

        [HttpGet]
        [Route("{id}/organization-units")]
        public Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id)
        {
            return _identityUserAppService.GetOrganizationUnitsAsync(id);
        }

        [HttpPut]
        [Route("{id}/lock/{seconds}")]
        public Task LockUserAsync(Guid id, double? seconds)
        {
            return _identityUserAppService.LockUserAsync(id, seconds);
        }

        [HttpPut]
        [Route("{id}/unlock/")]
        public Task UnLockUserAsync(Guid id)
        {
            return _identityUserAppService.UnLockUserAsync(id);
        }

        [HttpPut]
        [Route("{id}/extend")]
        public Task<IdentityUserDto> UpdateAsync(Guid id, ExtendIdentityUserUpdateDto input)
        {
            return _identityUserAppService.UpdateAsync(id, input);
        }
    }
}
